package com.controller.nginxset;

import javax.servlet.http.HttpServletResponse;

import org.lucksyc.utilindependent.resultview.core.data.ViewData;
import org.lucksyc.utilindependent.resultview.seed.deal.ViewBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.upper.service.nginxset.NginxSetInterface;

/**
 * @author wsq
 */
@Controller
@RequestMapping("/nginxset")
public class NginxSetController {
	private static final Logger log = LoggerFactory.getLogger(NginxSetController.class);
	
	@Autowired
	ViewBuilder viewBuilder;
	
	@Autowired
	NginxSetInterface nginxSetInterface;
	
	@ResponseBody
	@PostMapping("/uploadjson")
	public ViewData uploadjson(@RequestParam("file") MultipartFile file,boolean isMine) {
		log.info("ConfigController:uploadjson.");
		try {
			return nginxSetInterface.uploadjson(file, isMine);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
		return viewBuilder.failed();
	}

	
	@ResponseBody
	@GetMapping("/downloadjson")
	public void downloadjson(HttpServletResponse response) {
		log.debug("ConfigController:downloadjson.");
		try {
			nginxSetInterface.downloadjson(response);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
	}
	@ResponseBody
	@GetMapping("/downloadtable")
	public void downloadtable(HttpServletResponse response) {
		log.debug("ConfigController:downloadtable.");
		try {
			nginxSetInterface.downloadtable(response);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
	}
	
	@ResponseBody
	@GetMapping("/downloadconf")
	public void downloadconf(HttpServletResponse response,boolean isBs) {
		log.debug("ConfigController:downloadconf.");
		try {
			nginxSetInterface.downloadconf(response, isBs);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
	}
	
	@ResponseBody
	@GetMapping("/downloadorgconf")
	public void downloadorgconf(HttpServletResponse response) {
		log.debug("ConfigController:downloadorgconf.");
		try {
			nginxSetInterface.downloadorgconf(response);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info(e.getMessage());
		}
	}
}
